<?php
/**
 * 缓存类管理器
 * 
 * ============================================================================
 * 版权所有: (c) 2009-2011，<UEShop Inc>，并保留所有权利。
 * 网站地址: http://www.ueshop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 *
 * @author      cmpan
 * @copyright   Copyright (c) 2009-2011 UEShop Inc. (http://www.ueshop.cn)
 * @license     http://www.ueshop.cn/1_0.txt
 */
class UE_Upload {

	protected static $_instance = array();
	
	/**
	 * 获取数据库操作对象
	 *
	 * @param string $uploadDriver
	 * @return UE_Upload_Interface
	 */
	public static function factory($uploadHandler = '') {
		$uploadClass = 'UE_Upload_' . ucfirst(empty($uploadHandler) ? cfg('upload_handler') : $uploadHandler);
		
		if(empty(self::$_instance[$uploadClass])) {
			$file = LIBS_DIR . '/' . str_replace('_', '/', $uploadClass) . ".php";
			if (is_file($file)) {
				require_once $file;
			} else {
				throw new UE_Upload_Exception("Upload handler class ($uploadClass: $file) not exists");
			}
			self::$_instance[$uploadClass] = new $uploadClass();
		}
		
		return self::$_instance[$uploadClass];
	}
}
